feat: add --meta flag for document metadata#5
Conversation
Adds a --meta flag that displays document title, ID, revision, and all tabs with their IDs. Useful for discovering tab IDs before fetching specific tab content. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughA new Changes
Sequence DiagramsequenceDiagram
participant User as User/CLI
participant Main as main.showMeta
participant Auth as OAuth Authenticator
participant Docs as Google Docs API
participant Client as gdocs.Client
participant Render as Tab Renderer
User->>Main: --meta flag with URL
Main->>Main: Extract document ID from URL
Main->>Auth: Create authenticator & client
Auth->>Docs: OAuth flow
Docs-->>Auth: Auth token
Auth-->>Main: Ready
Main->>Client: Fetch document
Client->>Docs: Get document
Docs-->>Client: Document with tabs
Client-->>Main: docs.Document
Main->>Render: ListTabs(document)
Render->>Render: collectTabs (recursive)
Render-->>Main: []TabInfo
Main->>Main: Format & print metadata
Main-->>User: Display title, ID, tabs
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
cmd/gdocs-cli/main.go (1)
197-249: Move metadata fetch/format logic out ofmain.go.
showMetacurrently performs business logic (data shaping + rendering loop) inside the CLI entrypoint file. Consider moving this to an internal package/service and keepingmain.gofocused on orchestration.As per coding guidelines: "CLI entry point should contain no business logic, only flag parsing and orchestration".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/gdocs-cli/main.go` around lines 197 - 249, The showMeta function in main.go contains business logic (fetching, shaping and rendering metadata) that should be moved into an internal package; create a new service (e.g., internal/gdocmeta) that encapsulates the flow currently in showMeta: extract document ID (gdocs.ExtractDocumentID), authenticate (auth.NewAuthenticator / GetClient), create Docs client (gdocs.NewClient), fetch the document (client.FetchDocument) and produce a formatted representation (use gdocs.ListTabs to build tabs with Depth/Emoji/Title/ID) and expose a single function such as FetchAndFormatMeta(ctx, httpClient, docID) or FormatMetaFromDoc(doc) that returns a plain string or structured DTO; then replace showMeta in main.go with orchestration-only code that calls the new package function and prints its result, keeping main.go free of data-shaping and rendering loops.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/gdocs-cli/main.go`:
- Around line 70-77: Make --clean and --meta mutually exclusive by validating
flags early: if *cleanFlag && *metaFlag then print a clear error to stderr and
exit non-zero. Update main's flag-handling logic so the exclusivity check runs
before any branch (before calling showMeta or the normal output path), and
ensure showMeta is never called when cleanFlag is set; use the existing
metaFlag, cleanFlag, and showMeta symbols to locate the code to change.
---
Nitpick comments:
In `@cmd/gdocs-cli/main.go`:
- Around line 197-249: The showMeta function in main.go contains business logic
(fetching, shaping and rendering metadata) that should be moved into an internal
package; create a new service (e.g., internal/gdocmeta) that encapsulates the
flow currently in showMeta: extract document ID (gdocs.ExtractDocumentID),
authenticate (auth.NewAuthenticator / GetClient), create Docs client
(gdocs.NewClient), fetch the document (client.FetchDocument) and produce a
formatted representation (use gdocs.ListTabs to build tabs with
Depth/Emoji/Title/ID) and expose a single function such as
FetchAndFormatMeta(ctx, httpClient, docID) or FormatMetaFromDoc(doc) that
returns a plain string or structured DTO; then replace showMeta in main.go with
orchestration-only code that calls the new package function and prints its
result, keeping main.go free of data-shaping and rendering loops.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d0bda4b4-4fdc-4717-953a-32751b0f49a3
📒 Files selected for processing (2)
cmd/gdocs-cli/main.gointernal/gdocs/client.go
| // Handle meta mode | ||
| if *metaFlag { | ||
| if err := showMeta(*urlFlag, configPath); err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| return | ||
| } |
There was a problem hiding this comment.
--clean and --meta should be mutually exclusive.
At Line 38, --clean promises markdown-only stdout, but Line 72 routes to showMeta, which prints non-markdown output. This breaks clean-mode piping expectations.
💡 Proposed fix
// Handle clean mode - suppress all logs
if *cleanFlag {
log.SetOutput(io.Discard)
}
+
+ // Validate incompatible output modes
+ if *cleanFlag && *metaFlag {
+ fmt.Fprintln(os.Stderr, "Error: --clean and --meta cannot be used together")
+ os.Exit(1)
+ }As per coding guidelines: "The --clean flag should only output markdown to stdout, making it easy to pipe output directly into AI systems or other tools".
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Handle meta mode | |
| if *metaFlag { | |
| if err := showMeta(*urlFlag, configPath); err != nil { | |
| fmt.Fprintf(os.Stderr, "Error: %v\n", err) | |
| os.Exit(1) | |
| } | |
| return | |
| } | |
| // Handle clean mode - suppress all logs | |
| if *cleanFlag { | |
| log.SetOutput(io.Discard) | |
| } | |
| // Validate incompatible output modes | |
| if *cleanFlag && *metaFlag { | |
| fmt.Fprintln(os.Stderr, "Error: --clean and --meta cannot be used together") | |
| os.Exit(1) | |
| } | |
| // Handle meta mode | |
| if *metaFlag { | |
| if err := showMeta(*urlFlag, configPath); err != nil { | |
| fmt.Fprintf(os.Stderr, "Error: %v\n", err) | |
| os.Exit(1) | |
| } | |
| return | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@cmd/gdocs-cli/main.go` around lines 70 - 77, Make --clean and --meta mutually
exclusive by validating flags early: if *cleanFlag && *metaFlag then print a
clear error to stderr and exit non-zero. Update main's flag-handling logic so
the exclusivity check runs before any branch (before calling showMeta or the
normal output path), and ensure showMeta is never called when cleanFlag is set;
use the existing metaFlag, cleanFlag, and showMeta symbols to locate the code to
change.
Summary
--metaflag that displays document title, ID, revision ID, and all tabs (with nesting and emoji support)?tab=t.xxxUsage
gdocs-cli --meta --url="https://docs.google.com/document/d/DOC_ID/edit"Test plan
--metacorrectly lists tabs for multi-tab documents🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
--metaflag that displays document metadata (title, document ID, and revision ID) instead of converting to markdown.